/**
 * 表格的基本结构方法
 */
import { mapGetters } from 'vuex'
import { count } from '../../assets/js/help.js'
export default {
  computed: {
    ...mapGetters({
      isHideSideBar: 'getIsHideSideBar',
      isFullScreenTable: 'getFullScreenTable',
      isMask: 'getIsMask'
    })
  },

  created() {
    
  },

  watch: {
    tbodysInfo: function (val) {
      if (val.length > 0) {
        this.resetTableFn();
      }
    }
  },

  mounted() {
    let _this = this;
    let resize_timer = null;
    this.resetTableFn();
    $(window).on('resize', function () {
      clearTimeout(resize_timer);
      resize_timer = setTimeout(function () {
        this.isShowSetting = false;
        this.resetTableFn();
      }.bind(_this), 300);
    })
  },

  methods: {
    //处理表格checkbox多选
    handleSelectionChange(val) {
      this.multipleSelection = val;
      this.$emit('handleMultiCheck', val);
    },

    handleSortChange(sortInfo) {
      let type = sortInfo.order == null ? '' : sortInfo.order;
      let prop = sortInfo.prop == null ? '' : sortInfo.prop;
      let _name = this.$route.meta.name;
      let info = JSON.parse(localStorage.getItem(_name));
      let sortObj = {
        orderBy: prop,
        orderTy: type
      };
      this.orderBy = prop;
      this.orderTy = type;
      if (!info) { info = {}; }
      if (!prop && !type) {
        delete info.sort;
      } else {
        info['sort'] = sortObj;
      }
      if (count(info) > 0) {
        localStorage.setItem(_name, JSON.stringify(info));
      } else {
        localStorage.removeItem(_name);
      }
      type = type == '' ? '' : (type == 'ascending' ? 'ASC' : 'DESC');
      this.$emit('handleSortColumn', prop, type);
      this.$emit('searchFn');
    },

    //切换全屏表格状态
    toggleFullScreenTable() {
      this.$store.commit('FULLSCREENTABLE_TOGGLE');
      this.$store.commit('SIDEBAR_TOGGLE', this.isFullScreenTable);
      this.resetTableFn(true);
    },

    //隐藏树的选择框
    toggleTreeBox() {
      this.$emit('toggleTreeBox', 'show');
    },

    resetTableFn() {

    }

  }

}
